var models = require('../db');
var express = require('express');
var router = express.Router();
var router = express.Router();
var mysql = require('mysql');
var $sql = require('../sql');
// 连接数据库
var conn = mysql.createConnection(models.mysql);


conn.connect();
// 删除数据
router.get('/dataSummaryP', (req, res) => {
    var sql = $sql.dataSummary.provice;
    console.log(sql);
    conn.query(sql, [], function (err, result) {
        console.log(result);
        var data = JSON.parse(JSON.stringify(result))
        for(var i = 0;i<data.length;i++){
            data[i].value=parseInt(data[i].value)
            if (data[i].name =='黑龙'){
                data[i].name == "黑龙江"
            } else if(data[i].name =='内蒙'){
                data[i].name == "内蒙古"
            }
            else if(data[i].name =='南海'){
                data[i].name == "南海诸岛"
            }
        }
        console.log(data);
        return res.send({
        status: 200,
        msg: "查找",
        data:data
      })
    })
  }),
  router.get('/vioPie', (req, res) => {
    var sql = $sql.dataSummary.vioPie;
    console.log(sql);
    conn.query(sql, [], function (err, result) {
        console.log(result);
        var data = JSON.parse(JSON.stringify(result))
        console.log(data)
        return res.send({
        status: 200,
        msg: "查询成功",
        data:data
      })
    })
  })
  
  router.get('/nightPie', (req, res) => {
    var sql = $sql.dataSummary.nightPie;
    console.log(sql);
    conn.query(sql, [], function (err, result) {
        console.log(result);
        var data = JSON.parse(JSON.stringify(result))
        console.log(data)
        return res.send({
        status: 200,
        msg: "查询成功",
        data:data
      })
    })
  })
  router.get('/zhu', (req, res) => {
    var sql = $sql.dataSummary.zhu;
    console.log(sql);
    conn.query(sql, [], function (err, result) {
      var data = JSON.parse(JSON.stringify(result))
        console.log(data)
        return res.send({
        status: 200,
        msg: "查询成功",
        data:data
    })
    })
  })
module.exports = router;
